import { request } from '@umijs/max';
import React from 'react';

/** 分页查询机构 GET /system/org/list */
export async function getOrgList(params: API.QueryOrgListParams) {
  return request<API.QueryPageResp<API.Org>>('/system/org/list', {
    method: 'GET',
    params,
  });
}

/** 获取机构树 GET /system/org/get/trees */
export async function getOrgTrees() {
  return request<API.QueryOrgTreesResult>('/system/org/get/trees', {
    method: 'GET',
  });
}

/** 批量删除机构 POST /system/org/deletes */
export async function deleteOrgsByIdList(idList: React.Key[]) {
  return request<API.Resp>('/system/org/deletes', {
    method: 'POST',
    data: idList,
  });
}

/** 通过ID删除机构 POST /system/org/delete */
export async function deleteOrgById(id: React.Key) {
  return request<API.Resp>(`/system/org/delete`, {
    method: 'POST',
    params: {
      id,
    },
  });
}

/** 添加机构 POST /system/org/add */
export async function addOrg(params: API.Org) {
  return request<API.Resp>(`/system/org/add`, {
    method: 'POST',
    data: params,
  });
}

/** 更新机构 POST /system/org/update */
export async function updateOrg(params: API.Org) {
  return request<API.Resp>(`/system/org/update`, {
    method: 'POST',
    data: params,
  });
}

/** 根据机构ID查询机构信息 GET /system/org/get/{id} */
export async function getOrgByID(id: React.Key) {
  return request<API.Resp<API.Org>>(`/system/org/get/${id}`, {
    method: 'GET',
  });
}

/** 根据机构ID查询机构信息 POST /system/org/export */
export async function exportOrg(params: API.QueryOrgListParams) {
  return request<API.Resp>(`/system/org/export`, {
    method: 'POST',
    data: params,
  });
}
